package com.example.learn_gl_android.anglib.core.renderer.matrial

import com.example.learn_gl_android.anglib.util.MyGLUtil
import java.nio.FloatBuffer

data class IndexTexture(var colors : Array<Color>) {

    fun getColor(idx : Int) : Color{
        return colors[idx]
    }

    fun toFloatBuffer() : FloatBuffer {
        val ret = FloatBuffer.allocate(colors.size * 4)

        colors.forEach {
            ret.put(Color.toFloatBuffer(it))
        }
        return MyGLUtil.initFloatBuffer(ret.array())
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as IndexTexture

        return colors.contentEquals(other.colors)
    }

    override fun hashCode(): Int {
        return colors.contentHashCode()
    }
}